package com.neusoft.service.impl;

import com.neusoft.mapper.CheckRequestMapper;
import com.neusoft.mapper.MedicalTechnologyMapper;
import com.neusoft.service.CheckRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CheckRequestServiceImpl implements CheckRequestService {

    @Autowired
    CheckRequestMapper checkRequestMapper;

    @Autowired
    MedicalTechnologyMapper medicalTechnologyMapper;

    @Override
    public Integer getFinishCheck() {
        return checkRequestMapper.selectFinshCheck();
    }

    @Override
    public List<Integer> getWaitRegisterIdList() {
        return checkRequestMapper.selectWaitCheck();
    }

    @Override
    public void updateCheckRequestTable(Integer checkId, Integer employeeId) {
        LocalDateTime checkTime=LocalDateTime.now();
        checkRequestMapper.updateCheckRequestTable(checkId,employeeId,checkTime);
    }
    @Override
    public String saveCheckRequest(Map<String, Object> checkRequest) {

        //checkRequestMapper.insert(checkRequest);

        List<Map<String,Object>> checkMedicalTechnologyList=(List<Map<String, Object>>) checkRequest.get("checkMedicalTechnologyList");

        if (checkMedicalTechnologyList.size()>0){
            for (int i=0;i<checkMedicalTechnologyList.size();i++){
                Map<String,Object> element=checkMedicalTechnologyList.get(i);
                checkRequest.put("medical_technology_id",element.get("id"));
                checkRequest.put("check_state","已开立");
               // checkRequest.put("checkMedicalTechnologyList",element);
                checkRequestMapper.insert(checkRequest);
            }
        }

        return "成功";
    }
}
